<template>
  <div class="boxCon">
    <div class="itemTitle">
      <span class="text gradient-text">易访客户</span>
    </div>
    <div class="flex-container">
      <div class="flex-container-rest">
        <div v-for="item in data" :key="item.title" class="flex-item">
          <div class="dataItem flx-center mb10 hoverIcon" @click="HandleCli(item.title)">
            <span class="dataName hoverIcon">{{ item.title }}</span>
            <b :class="getRowClasses(item.status)">{{ item.val }}</b>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from "vue";

const emit = defineEmits(["clickEvent"]);
const data = ref([
  { title: "易访用户数", val: 1167290, status: "down" },
  { title: "已触达数", val: 727831, status: "down" },
  { title: "确认友好客户数", val: 294412, status: "up" },
  { title: "低满待修复", val: 15688, status: "info" },
  { title: "修复完成数", val: 15090, status: "normal" },
  { title: "修复成功数", val: 10967, status: "up" },
  { title: "已质检量", val: 113229, status: "up" }
]);
const HandleCli = (item: any) => {
  emit("clickEvent", "易访库用户跟进", [item]);
};

const statusClasses = {
  down: ["warning-row"],
  up: ["success-row"],
  info: ["info-row"],
  default: ["default-row"]
};

const getRowClasses = computed(() => {
  return status => {
    // 使用扩展运算符和逻辑或操作符确保返回至少一个类名
    return ["dataValue", ...(statusClasses[status] || ["default-row"])];
  };
});
</script>

<style scoped lang="scss">
.boxCon {
  position: relative;
  flex: 1;
  padding: 10px;
  margin-top: 8px;
  border: 1px solid rgb(18 177 254 / 20%);
  border-top: none;
  .flex-item {
    box-sizing: border-box;
    flex: 1 1 50%; /* Adjust width as needed */
    padding: 0 10px;
  }
  .flex-container {
    display: flex;
    flex-wrap: wrap; /* 允许项目换行 */
  }
  .flex-item:first-child {
    flex: 1 1 100%;
  }
  .flex-container-rest {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
  }
  .dataItem {
    height: 32px;
    padding: 0 8px;
    cursor: pointer;
    background-image: linear-gradient(270deg, rgb(40 115 255 / 4%) 0%, rgb(40 115 255 / 16%) 99%);
    .dataName {
      font-family: YouSheBiaoTiHei;
      font-size: 18px;
      line-height: 20px;
      color: #ffffff;
    }
  }
  .dataItem:hover {
    background: rgb(40 115 255 / 30%) 99%;
  }
  .itemTitle {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 1px;
    &::before {
      display: inline-block;
      flex: 1;
      height: 1px;
      margin-right: 8px;
      content: "";
      background: rgb(18 177 254 / 20%);
    }
    &::after {
      display: inline-block;
      flex: 1;
      height: 1px;
      margin-left: 8px;
      content: "";
      background: rgb(18 177 254 / 20%);
    }
    .text {
      position: relative;
      font-family: YouSheBiaoTiHei;
      font-size: 25px;
      &::before {
        position: absolute;
        top: 8px;
        left: -8px;
        display: inline-block;
        width: 2px;
        height: 6px;
        content: "";
        background: #fedb2c;
      }
      &::after {
        position: absolute;
        top: 8px;
        right: -8px;
        display: inline-block;
        width: 2px;
        height: 6px;
        content: "";
        background: #fedb2c;
      }
    }
    .gradient-text {
      /* 使用透明度来实现文字渐变效果 */
      color: transparent;

      /* 使文字不可选中 */
      user-select: none;

      /* 线性渐变从白色到蓝色 */
      background: linear-gradient(to bottom, #ffffff, #85c0ed);

      /* 使用背景色填充文字 */
      background-clip: text;
    }
  }
  .hoverIcon {
    &::before {
      position: absolute;
      bottom: 0;
      left: 0;
      box-sizing: border-box;
      display: inline-block;
      width: 6px;
      height: 6px;
      content: "";
      border-bottom: 1px solid #27d7ff;
      border-left: 1px solid #27d7ff;
    }
    &::after {
      position: absolute;
      right: 0;
      bottom: 0;
      box-sizing: border-box;
      display: inline-block;
      width: 6px;
      height: 6px;
      content: "";
      border-right: 1px solid #27d7ff;
      border-bottom: 1px solid #27d7ff;
    }
  }
}
</style>
